/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.util.ArrayList;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;

/**
 *
 * @author niennd
 */
public class StopTask implements Runnable {
    private ArrayList<ScheduledFuture<?>> listSchedFuture;
    private ScheduledExecutorService executorService;
    private Command stopCommand;

    public StopTask(ArrayList<ScheduledFuture<?>> listSchedFuture, ScheduledExecutorService executorService, Command stopCommand) {
        this.listSchedFuture = listSchedFuture;
        this.executorService = executorService;
        this.stopCommand = stopCommand;
    }
    
    @Override
    public void run() {
        stopCommand.execute();
        for (ScheduledFuture<?> fSchedFuture : listSchedFuture) {
            fSchedFuture.cancel(true);
        }
        executorService.shutdown();
    }
}